﻿namespace NFinal
{
    /// <summary>
    /// Session
    /// </summary>
    public class Session:ISession
    {
        /// <summary>
        /// Session ID
        /// </summary>
        protected string sessionId = null;
        /// <summary>
        /// 缓存类
        /// </summary>
        private ICache cache = null;
        public Session(string sessionId,ICache cache)
        {
            this.sessionId = sessionId;
            this.cache = cache;
        }
        public byte[] Get(string key)
        {
            return cache.Get(Constant.SessionChannel+sessionId + key);
        }
        public T Get<T>(string key)
        {
            return cache.Get<T>(Constant.SessionChannel + sessionId + key);
        }
        public void Set(string key, object value)
        {
            cache.Set(Constant.SessionChannel + sessionId + key, value);
        }
        public void Set<T>(string key, T t)
        {
            cache.Set<T>(Constant.SessionChannel + sessionId + key, t);
        }
        public void Set(string key,string value)
        {
            cache.SetString(Constant.SessionChannel + sessionId + key, value);
        }
        public string this[string key]
        {
            get {
               return Get<string>(key);
            }
            set {
                Set<string>(key, value);
            }
        }
    }
}
